#ifndef _ZENGL_ENGINE_H_
#define _ZENGL_ENGINE_H_

#include "StrawGUI.h"
#include "zglConfig.h"
#include "sControllerEvents.h"

namespace sgui
{
namespace engine
{

class zglTexture;
class zglFont;
class zglDrawContext;
class zglRenderTarget;

class zglEngine : public sEngine
{
private:
	static const int KEY_MAPPINGS_DEF[obs::sKeyboardEvent::KEY_COUNT];
private:

	static const zglTPoint2D toPosition2d(const sgui::math::sPointf& p)
    {
		zglTPoint2D pt = {p.X, p.Y};
        return pt;
    }

	static const zglTRect toRect(const sgui::math::sRectf& p)
    {
		zglTRect rct = { p.X, p.Y, p.W, p.H };

		return rct;
    }

private:
	math::sPointf		m_lastMousePos;
	std::map<int, int>	m_keyMappings;
	bool				m_readTextMode;
private:

    friend zglFont;
    friend zglTexture;
    friend zglDrawContext;
    friend zglRenderTarget;
public:
    sTexture* getTexture(const res::sTextureResource& res, const preset::sTexturePreset& preset);
    sFont* getFont(const res::sFontResource& res, const preset::sFontPreset& preset);
	sRenderTarget* getRenderTarget(const math::sPointf& size);

	void getContext(void *memory, const math::sRectf& rect, bool clipRect = true) const;
	void getContext(void *memory, const math::sRectf& rect, const sDrawContext* parentContext, bool clipRect = true) const;
	u32 getContextMemorySize() const;
	math::sPointf retreiveScreenSize() const;
	void update(double dt);
	
	void textBeginRead();
	void textEndRead();

	void setScissor(const math::sRectf& rect, sDrawSurface& surface) const;
	void removeScissor() const;

	void beginRender(sDrawStack& stack) const;
	void endRender(sDrawStack& stack) const;

	void drawRect(const math::sRectf& rect, u32 color = 0xFFFFFFFF, bool fill = false) const;

    zglEngine();
};

};
};

#endif